package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.NursingHome;
import com.example.elderlycare.dao.mapper.NursingHomeMapper;
import com.example.elderlycare.service.NursingHomeService;
import com.example.elderlycare.service.entity.NursingHomeListResponseBody;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class NursingHomeServiceImpl extends ServiceImpl<NursingHomeMapper, NursingHome>
        implements NursingHomeService {
    @Resource
    NursingHomeMapper nursingHomeMapper;

    @Override
    public NursingHomeListResponseBody queryNursingHome(int current, int pageSize, QueryWrapper<NursingHome> queryWrapper) {
        Page<NursingHome> page = new Page<>(current, pageSize);
        Page<NursingHome> nursingHomePage = nursingHomeMapper.selectPage(page, queryWrapper);
        return NursingHomeListResponseBody.builder()
                .total(Math.toIntExact(nursingHomePage.getTotal()))
                .nursingHomeList(nursingHomePage.getRecords())
                .build();
    }
}
